<template>
	<view class="serveOrderdetail">
		<view class="statusBox">
			<image :src="imaurl+'d5.png'" style="width: 48rpx;height: 48rpx;" mode=""></image>
			<view v-if=" pageData.status == 1" class="" style="margin-left: 20rpx;">
				请立即支付
			</view>
			<view v-if=" pageData.status == 2" class="" style="margin-left: 20rpx;">
				等待鸽友寄送
			</view>
			<view v-if="pageData.status == 3" class="" style="margin-left: 20rpx;">
				鸽友已寄出，待反馈检测报告
			</view>
			<view v-if="pageData.status == 4" class="" style="margin-left: 20rpx;">
				订单服务已完成
			</view>
		</view>


		<view class="ljjs_content">
			<view v-if="pageData.status == 1" class="topcontent">
				<view class="right">
				</view>
				<view class="btns" @click="handlePay">
					立即支付
				</view>
			</view>
			<view v-if="pageData.status == 2" class="topcontent">
				<view class="right">
					请将送检的羽毛寄到该地址
				</view>
				<view class="btns" @click="show = true">
					立即寄出
				</view>
			</view>
			<view v-else class="titleBox">
				<view class="shu"></view>
				<view class="">
					寄送信息
				</view>
			</view>
			<view class="addressBox">
				<view class="nameprice">
					<text>{{pageData.post_name}}</text><text>{{pageData.post_mobile}}</text>
				</view>
				<view class="addresstext">
					{{pageData.post_address}}
				</view>
			</view>
			<view v-if="pageData.status == 3 || pageData.status == 4" class="">
				<view class="messageItem">
					<view class="lable">
						快递公司
					</view>
					<view class="value">
						{{pageData.express_company}}
					</view>
				</view>
				<view class="messageItem">
					<view class="lable">
						快递单号
					</view>
					<view class="value">
						{{pageData.express_number}}
					</view>
				</view>
			</view>
		</view>


		<view class="jsmessage_content">
			<view class="titleBox">
				<view class="shu"></view>
				<view class="">
					服务信息
				</view>
			</view>
			<view class="serveitem" style="margin-top: 20rpx;">
				<image :src="pageData.image" style="width: 144rpx;height: 144rpx;border-radius: 10rpx;" mode="">
				</image>
				<view class="servemessage">
					<view class="name">
						{{pageData.sname}}
					</view>
					<view class="desc">
						{{pageData.sinfo}}
					</view>
				</view>
				<view class="price">
					￥{{pageData.order_price}}
				</view>
			</view>
			<view class="messageItem">
				<view class="lable">
					服务总额
				</view>
				<view class="value">
					￥{{pageData.order_price}}
				</view>
			</view>
			<view class="messageItem">
				<view class="lable">
					实付款
				</view>
				<view class="value">
					￥{{pageData.order_tol}}
				</view>
			</view>
		</view>


		<view v-if="pageData.status == 4" class="jsmessage_content">
			<view class="titleBox">
				<view class="shu"></view>
				<view class="">
					检测报告
				</view>
				<view class="save" @click="saveFun">
					一键保存
				</view>
			</view>
			<view class="imaBox">
				<image v-for="(item,index) in BGListL" :src="item"
					style="width: 160rpx;height: 160rpx;border-radius: 20rpx;margin-right: 10rpx;" mode=""
					@click="handleImg(BGListL,index)"></image>
			</view>
		</view>

		<view class="jsmessage_content">
			<view class="titleBox">
				<view class="shu"></view>
				<view class="">
					鸽子信息
				</view>
			</view>
			<view class="contentitem">
				<view class="item">
					<view class="lable">
						环号
					</view>
					<view class="value">
						{{pageData.ring}}
					</view>
				</view>
				<view class="item">
					<view class="lable">
						羽色
					</view>
					<view class="value">
						{{pageData.color}}
					</view>
				</view>
			</view>
		</view>


		<view class="jsmessage_content">
			<view class="titleBox">
				<view class="shu"></view>
				<view class="">
					订单信息
				</view>
			</view>
			<view class="messageItem">
				<view class="lable">
					订单编号
				</view>
				<view class="value">
					{{pageData.order_sn}}
				</view>
			</view>
			<view class="messageItem">
				<view class="lable">
					下单时间
				</view>
				<view class="value">
					{{pageData.addtime}}
				</view>
			</view>
			<view class="messageItem">
				<view class="lable">
					支付时间
				</view>
				<view class="value">
					{{pageData.paytime ==null?'':pageData.paytime}}
				</view>
			</view>
			<view class="messageItem">
				<view class="lable">
					支付方式
				</view>
				<view class="value">
					微信支付
				</view>
			</view>
		</view>

		<view class="" style="height: 100rpx;"></view>


		<u-popup :show="show" :round="20" :closeable="true" :closeOnClickOverlay="true" @close="show = false">
			<view class="contentBox">
				<view class="title">
					快递寄送
				</view>
				<view class="content">
					<view class="inpuBox">
						<view class="lable">
							快递公司
						</view>
						<input class="inputitem" type="text" v-model="express_company" placeholder="请输入您的快递公司" />
					</view>

					<view class="inpuBox">
						<view class="lable">
							快递单号
						</view>
						<input class="inputitem" type="text" v-model="express_number" placeholder="请输入您的快递单号" />
					</view>
				</view>


				<view class="btns" @click="handlecofirmsend">
					确认寄送
				</view>


			</view>
		</u-popup>

	</view>
</template>

<script>
	import {
		serviceorderinfo,
		cofirmsend
	} from "@/api/api.js"
	export default {
		data() {
			return {
				pageId: "",
				pageData: {},
				show: false,
				express_company: "", //快递公司
				express_number: "", //快递单号
				imaurl: "https://szgb.tongchengbang.cc/img/image/",
				BGListL: [], //报告数据
			}
		},
		onLoad(options) {
			console.log("id", options.id)
			this.pageId = options.id
			this.handleGetServeOrderdetail()
		},
		methods: {
			async handleGetServeOrderdetail() {
				let res = await serviceorderinfo({
					oid: this.pageId
				})
				this.pageData = res.data
				if (this.BGListL) {
					this.BGListL = this.pageData.reports.split(",")
				}
				// console.log("11", this.BGListL)
			},
			handlePay() {

			},
			async handlecofirmsend() {
				if (this.express_company == "") {
					uni.showToast({
						title: "请输入快递公司！",
						icon: "none",
						duration: 2000
					});
					return
				}
				if (this.express_number == "") {
					uni.showToast({
						title: "请输入快递单号！",
						icon: "none",
						duration: 2000
					});
					return
				}
				let data = {
					oid: this.pageId,
					express_company: this.express_company,
					express_number: this.express_number
				}
				let res = await cofirmsend(data)
				if (res.code == 1) {
					this.show = false
					uni.showToast({
						title: res.msg,
						icon: "none",
						duration: 2000
					});
					setTimeout(() => {
						this.handleGetServeOrderdetail()
					}, 2000)
				} else {
					uni.showToast({
						title: res.msg,
						icon: "none",
						duration: 2000
					});
				}
			},

			handleImg(img, index) {
				uni.previewImage({
					current: index, // 当前显示图片的链接（必填）
					urls: img, // 要预览的图片链接列表（必填）
					success() {},
					fail(err) {}
				});
			},

			saveFun() {
				let videolength = this.BGListL.length; // 要下载的总条数
				uni.showLoading({
					title: '图片下载中',
					mask: true
				});
				let that = this;
				let index = 0;
				for (let i = 0; i < this.BGListL.length; i++) {
					uni.downloadFile({
						url: that.BGListL[i],
						success: function(res) {
							var temp = res.tempFilePath
							uni.saveImageToPhotosAlbum({
								filePath: temp,
								success(res1) {
									index++;
									// 全部下载完后触发
									if (index == videolength) {
										uni.showToast({
											title: "保存成功",
											icon: "none",
											duration: 2000
										});
									}
								},
							})
						}
					})
				}
			},


		}
	}
</script>

<style scoped lang="scss">
	.messageItem {
		display: flex;
		align-items: center;
		width: 100%;
		padding: 20rpx;
		box-sizing: border-box;
		justify-content: space-between;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #666666;
		line-height: 33rpx;
	}

	.contentBox {
		padding-top: 30rpx;
		width: 100%;

		.title {
			width: 100%;
			text-align: center;
		}

		.content {
			margin-top: 50rpx;
			width: 100%;
			padding: 30rpx;
			box-sizing: border-box;

			.inpuBox {
				margin-bottom: 50rpx;

				.lable {}

				.inputitem {
					width: 670rpx;
					height: 104rpx;
					background: #F6F6F6;
					border-radius: 20rpx 20rpx 20rpx 20rpx;
					margin-top: 20rpx;
					padding-left: 30rpx;
					box-sizing: border-box;
				}
			}

		}

		.btns {
			width: 630rpx;
			height: 88rpx;
			background: #00BF52;
			border-radius: 200rpx 200rpx 200rpx 200rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 88rpx;
			text-align: center;
			margin: 0 auto;
		}
	}

	.serveOrderdetail {
		.statusBox {
			width: 750rpx;
			height: 108rpx;
			background: #FFF5CC;
			padding: 30rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 32rpx;
			color: #333333;
			// line-height: 38rpx;
		}

		.titleBox {
			font-family: PingFang SC, PingFang SC;
			font-weight: 800;
			font-size: 32rpx;
			color: #333333;
			line-height: 38rpx;
			display: flex;
			align-items: center;

			.shu {
				width: 8rpx;
				height: 32rpx;
				background: #00BF52;
				border-radius: 200rpx 200rpx 200rpx 200rpx;
				margin-right: 20rpx;
			}
		}

		.addressBox {
			width: 690rpx;
			height: 160rpx;
			background: #F6F6F6;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			margin-top: 20rpx;
			padding: 30rpx;
			box-sizing: border-box;

			.nameprice {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #333333;
				line-height: 33rpx;
			}

			.addresstext {
				width: 584rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #666666;
				line-height: 28rpx;
				margin-top: 18rpx;
			}
		}

		.ljjs_content {
			width: 750rpx;
			background: #FFFFFF;
			padding: 30rpx;
			box-sizing: border-box;
			margin-top: 20rpx;

			.topcontent {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.right {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 32rpx;
					color: #333333;
					line-height: 38rpx;
				}

				.btns {
					width: 240rpx;
					height: 68rpx;
					background: #00BF52;
					border-radius: 200rpx 200rpx 200rpx 200rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 32rpx;
					color: #FFFFFF;
					line-height: 68rpx;
					text-align: center;
				}
			}


		}

		.jsmessage_content {
			width: 750rpx;
			background: #FFFFFF;
			padding: 30rpx;
			box-sizing: border-box;
			margin-top: 20rpx;

			.messageItem {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 30rpx;

				.lable {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #666666;
					line-height: 33rpx;
				}

				.value {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #333333;
					line-height: 33rpx;
				}
			}

			.serveitem {
				display: flex;
				align-content: center;
				align-items: center;
				width: 690rpx;
				height: 184rpx;
				background: #F6F6F6;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				padding: 20rpx;
				box-sizing: border-box;
				margin-bottom: 20rpx;

				.servemessage {
					width: 340rpx;
					margin-left: 20rpx;
					height: 144rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.name {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 32rpx;
						color: #333333;
						line-height: 38rpx;
					}

					.desc {
						width: 370rpx;
						height: 80rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #999999;
						line-height: 33rpx;
					}
				}

				.price {
					font-family: DIN, DIN;
					font-weight: 500;
					font-size: 36rpx;
					color: #E40700;
					line-height: 42rpx;
					// margin-left: 30rpx;
				}
			}

			.contentitem {
				display: flex;
				align-items: center;
				margin-top: 30rpx;

				.item {
					display: flex;
					align-items: center;
					width: 50%;

					.lable {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #333333;
						line-height: 33rpx;
					}

					.value {
						width: 254rpx;
						height: 80rpx;
						background: #F6F6F6;
						border-radius: 20rpx 20rpx 20rpx 20rpx;
						padding: 20rpx;
						box-sizing: border-box;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #333333;
						margin-left: 20rpx;
					}
				}

			}

			.save {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #00BF52;
				line-height: 33rpx;
				text-align: left;
				margin-left: 422rpx;
			}

			.imaBox {
				margin-top: 30rpx;
				flex-wrap: wrap;
			}
		}

	}
</style>